package edu.hgnu.consumer;

import com.rabbitmq.client.*;
import edu.hgnu.utils.RabbitMQUtils;

import java.io.IOException;

/**
 * @author admin
 */
public class Consumer1 {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMQUtils.getConnection();
        //方便改动
        String exchangeName = "exchange_1";
        String routingKey = "user.#";

        Channel channel = connection.createChannel();
        channel.exchangeDeclare(exchangeName,"topic");
        String queue = channel.queueDeclare().getQueue();

        channel.queueBind(queue,exchangeName, routingKey);
        channel.basicConsume(queue,true,new DefaultConsumer(channel){
            /**
             * @param consumerTag
             * @param envelope
             * @param properties
             * @param body
             */
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1："+new String(body));
            }
        });
    }
}
